<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><title>React - 实现一个基于 Antd 的密码强度校验组件 | Cyan</title><meta name="author" content="Cyan,843348394@qq.com"><meta name="copyright" content="Cyan"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="最近在开发 Nest 和 Umi 技术栈的个人项目，在用户管理模块需要用到一个密码强度校验组件，在网上寻找一方资料，没有找到自己想要的，特此自己造轮子！  效果预览 组件思想 既然是密码强度校验，那么强度就必须有个梯度，这个时候就必须找到一个合适的效果。 我们有两种方向：① 组件库找个合适的 UI ， ② 自己开发造轮子 经过一番摸索， Antd 的 Progress 组件进入了我的视野："><meta property="og:type" content="article"><meta property="og:title" content="React - 实现一个基于 Antd 的密码强度校验组件"><meta property="og:url" content="https://xmwpro.com/post/e140163a.html"><meta property="og:site_name" content="Cyan"><meta property="og:description" content="最近在开发 Nest 和 Umi 技术栈的个人项目，在用户管理模块需要用到一个密码强度校验组件，在网上寻找一方资料，没有找到自己想要的，特此自己造轮子！  效果预览 组件思想 既然是密码强度校验，那么强度就必须有个梯度，这个时候就必须找到一个合适的效果。 我们有两种方向：① 组件库找个合适的 UI ， ② 自己开发造轮子 经过一番摸索， Antd 的 Progress 组件进入了我的视野："><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://ali-oss.xmwpro.com/global/avatar.jpg"><meta property="article:published_time" content="2023-01-16T16:35:22.000Z"><meta property="article:modified_time" content="2023-06-26T09:26:36.564Z"><meta property="article:author" content="Cyan"><meta property="article:tag" content="组件封装"><meta property="article:tag" content="React"><meta property="article:tag" content="And Design"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://ali-oss.xmwpro.com/global/avatar.jpg"><link rel="shortcut icon" href="https://ali-oss.xmwpro.com/global/favicon.ico"><link rel="canonical" href="https://xmwpro.com/post/e140163a.html"><link rel="preconnect" href="//cdn.jsdelivr.net"><link rel="preconnect" href="//www.google-analytics.com" crossorigin=""><link rel="preconnect" href="//hm.baidu.com"><meta name="baidu-site-verification" content="codeva-yHszJZWbvj"><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://ali-oss.xmwpro.com/cdn/css/all.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://ali-oss.xmwpro.com/cdn/css/snackbar.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://ali-oss.xmwpro.com/cdn/css/fancybox.css" media="print" onload='this.media="all"'><script>var _hmt=_hmt||[];!function(){var e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?81fae81fdc8992b3e6ca314f289131e8";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}()</script><script async src="https://www.googletagmanager.com/gtag/js?id=G-2P0LMHZNDD"></script><script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","G-2P0LMHZNDD")</script><script>const GLOBAL_CONFIG={root:"/",algolia:{appId:"2Q4I5JDAJR",apiKey:"2ec9f676fd9c568eb0abedad38d16fe6",indexName:"Hexo",hits:{per_page:6},languages:{input_placeholder:"输入关键词快速查找",hits_empty:"找不到您查询的内容：${query}",hits_stats:"找到 ${hits} 条结果，用时 ${time} 毫秒"}},localSearch:void 0,translate:{defaultEncoding:2,translateDelay:0,msgToTraditionalChinese:"繁",msgToSimplifiedChinese:"簡"},noticeOutdate:void 0,highlight:{plugin:"highlighjs",highlightCopy:!0,highlightLang:!0,highlightHeightLimit:200},copy:{success:"复制成功",error:"复制错误",noSupport:"浏览器不支持"},relativeDate:{homepage:!1,post:!1},runtime:"天",date_suffix:{just:"刚刚",min:"分钟前",hour:"小时前",day:"天前",month:"个月前"},copyright:{limitCount:50,languages:{author:"作者: Cyan",link:"链接: ",source:"来源: Cyan",info:"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},lightbox:"fancybox",Snackbar:{chs_to_cht:"你已切换为繁体",cht_to_chs:"你已切换为简体",day_to_night:"你已切换为深色模式",night_to_day:"你已切换为浅色模式",bgLight:"var(--cyan-theme-color)",bgDark:"var(--cyan-theme-color)",position:"top-center"},source:{justifiedGallery:{js:"https://ali-oss.xmwpro.com/cdn/js/fjGallery.min.js",css:"https://ali-oss.xmwpro.com/cdn/css/fjGallery.css"}},isPhotoFigcaption:!0,islazyload:!0,isAnchor:!1,percent:{toc:!1,rightside:!0}}</script><script id="config-diff">var GLOBAL_CONFIG_SITE={title:"React - 实现一个基于 Antd 的密码强度校验组件",isPost:!0,isHome:!1,isHighlightShrink:!1,isToc:!0,postUpdate:"2023-06-26 09:26:36"}</script><noscript><style>#nav{opacity:1}.justified-gallery img{opacity:1}#post-meta time,#recent-posts time{display:inline!important}</style></noscript><script>(e=>{e.saveToLocal={set:function(e,t,o){if(0===o)return;const n=864e5*o,a={value:t,expiry:(new Date).getTime()+n};localStorage.setItem(e,JSON.stringify(a))},get:function(e){const t=localStorage.getItem(e);if(!t)return;const o=JSON.parse(t);if(!((new Date).getTime()>o.expiry))return o.value;localStorage.removeItem(e)}},e.getScript=e=>new Promise(((t,o)=>{const n=document.createElement("script");n.src=e,n.async=!0,n.onerror=o,n.onload=n.onreadystatechange=function(){const e=this.readyState;e&&"loaded"!==e&&"complete"!==e||(n.onload=n.onreadystatechange=null,t())},document.head.appendChild(n)})),e.getCSS=e=>new Promise(((t,o)=>{const n=document.createElement("link");n.rel="stylesheet",n.href=e,n.onload=()=>t(),n.onerror=()=>o(),document.head.appendChild(n)})),e.activateDarkMode=function(){document.documentElement.setAttribute("data-theme","dark"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#0d0d0d")},e.activateLightMode=function(){document.documentElement.setAttribute("data-theme","light"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#ffffff")};const t=saveToLocal.get("theme"),o=(new Date).getHours();void 0===t?o<=6||o>=18?activateDarkMode():activateLightMode():"light"===t?activateLightMode():activateDarkMode();const n=saveToLocal.get("aside-status");void 0!==n&&("hide"===n?document.documentElement.classList.add("hide-aside"):document.documentElement.classList.remove("hide-aside"));/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)&&document.documentElement.classList.add("apple")})(window)</script><link rel="stylesheet" href="//at.alicdn.com/t/c/font_3348168_pqjhlyxfz9r.css" media="defer" onload='this.media="all"'><link rel="stylesheet" href="https://ali-oss.xmwpro.com/cdn/css/swiper-bundle.min.css"><link rel="stylesheet" href="https://ali-oss.xmwpro.com/cdn/css/tianli_gpt.css"><script src="https://ali-oss.xmwpro.com/cdn/js/swiper-bundle.min.js"></script><script data-pjax src="https://ali-oss.xmwpro.com/cdn/js/jquery-3.3.1.js"></script><script data-pjax src="https://ali-oss.xmwpro.com/cdn/js/echarts.min.js"></script><script charset="UTF-8" id="LA_COLLECT" src="https://sdk.51.la/js-sdk-pro.min.js"></script><script src="https://ali-oss.xmwpro.com/cdn/js/three.min.js"></script><link rel="stylesheet" href="https://ali-oss.xmwpro.com/cdn/css/font-awesome-animation.min.css" media="defer" onload='this.media="all"'><link rel="stylesheet" href="https://ali-oss.xmwpro.com/cdn/css/tag_plugins.css" media="defer" onload='this.media="all"'><link rel="stylesheet" href="https://ali-oss.xmwpro.com/cdn/css/animate.min.css" media="print" onload='this.media="screen"'><link rel="stylesheet" href="https://ali-oss.xmwpro.com/cdn/css/gitcalendar.css" media="print" onload='this.media="all"'><meta name="generator" content="Hexo 5.4.2"><link rel="alternate" href="/atom.xml" title="Cyan" type="application/atom+xml"></head><body><div id="loading-box" onclick="document.getElementById(&quot;loading-box&quot;).classList.add(&quot;loaded&quot;)"><div class="loading-bg"><div class="loading-img"></div><div class="loading-image-dot"></div></div></div><script>const preloader={endLoading:()=>{document.body.style.overflow="auto",document.getElementById("loading-box").classList.add("loaded")},initLoading:()=>{document.body.style.overflow="",document.getElementById("loading-box").classList.remove("loaded")}};window.addEventListener("load",(()=>{preloader.endLoading()})),document.addEventListener("pjax:send",(()=>{preloader.initLoading()})),document.addEventListener("pjax:complete",(()=>{preloader.endLoading()}))</script><link rel="stylesheet" href="https://ali-oss.xmwpro.com/cdn/css/progress_bar.css"><script src="https://ali-oss.xmwpro.com/cdn/js/pace.min.js"></script><div id="web_bg"></div><div id="music_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/global/avatar.jpg" onerror='onerror=null,src="/img/friend_404.gif"' alt="avatar"></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">48</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">23</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div><hr><div class="menus_items"><div class="menus_item"><a class="site-page group faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw faa-tada fas fa-book"></i> <span>文库</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/archives/"><i class="fa-fw faa-tada fa-solid fa-box-archive"></i> <span>全部文章</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/tags/"><i class="fa-fw faa-tada fas fa-tags"></i> <span>标签</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/categories/"><i class="fa-fw faa-tada fas fa-shapes"></i> <span>分类</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw faa-tada fab fa-artstation"></i> <span>社交</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/link/"><i class="fa-fw faa-tada fa-solid fa-link"></i> <span>友人帐</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/fcircle/"><i class="fa-fw faa-tada fa-solid fa-user-group"></i> <span>朋友圈</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/guestbook/"><i class="fa-fw faa-tada fa-solid fa-envelope"></i> <span>留言板</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw faa-tada fas fa-coffee"></i> <span>休闲</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/music/"><i class="fa-fw faa-tada fa-solid fa-music"></i> <span>音乐馆</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/photoAlbum/"><i class="fa-fw faa-tada fa-solid fa-camera"></i> <span>相册</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/essay/"><i class="fa-fw faa-tada fa-solid fa-message"></i> <span>哔哔</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw faa-tada fa-solid fa-earth-asia"></i> <span>本站</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/analysis/"><i class="fa-fw faa-tada fa-solid fa-chart-simple"></i> <span>博客统计</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/about/"><i class="fa-fw faa-tada fa-regular fa-address-card"></i> <span>关于我</span></a></li></ul></div></div></div></div><div class="canvas-container" id="canvas"></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image:url('https://ali-oss.xmwpro.com/posts/post_cover33.jpg')"><nav id="nav"><span id="blog-info"><div class="back-home-button" tabindex="-1"><i class="back-home-button-icon fas fa-grip-vertical"></i><div class="back-menu-list-groups"><div class="back-menu-list-group"><div class="back-menu-list-title">社交</div><div class="back-menu-list"><a class="back-menu-item" href="https://xmwpro.com/" title="白雾茫茫丶" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="" data-lazy-src="https://ali-oss.xmwpro.com/global/avatar.jpg"><span class="back-menu-item-text">白雾茫茫丶</span></a><a class="back-menu-item" href="https://github.com/Cyan-Xmw/" rel="external nofollow noreferrer" title="Github" target="_blank" one-link-mark="yes"><i class="iconfont cyan-gitHub"></i><span class="back-menu-item-text">Github</span></a><a class="back-menu-item" href="https://gitee.com/Cyan-Xmw/" rel="external nofollow noreferrer" title="Gitee" target="_blank" one-link-mark="yes"><i class="iconfont cyan-gitee"></i><span class="back-menu-item-text">Gitee</span></a><a class="back-menu-item" href="https://juejin.cn/user/1917147257534279/" rel="external nofollow noreferrer" title="掘金" target="_blank" one-link-mark="yes"><i class="iconfont cyan-juejin"></i><span class="back-menu-item-text">掘金</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">项目</div><div class="back-menu-list"><a class="back-menu-item" href="https://docs.xmwpro.com/" rel="external nofollow noreferrer" title="Cyan Docs" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="" data-lazy-src="https://ali-oss.xmwpro.com/project/xmw-dumi-docs/logo.svg"><span class="back-menu-item-text">Cyan Docs</span></a><a class="back-menu-item" href="http://react.xmwpro.com/" rel="external nofollow noreferrer" title="Xmw-Admin" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="" data-lazy-src="https://ali-oss.xmwpro.com/pages/resource/xmw-admin.svg"><span class="back-menu-item-text">Xmw-Admin</span></a><a class="back-menu-item" href="http://vue3.xmwpro.com/" rel="external nofollow noreferrer" title="Vue3-Admin" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="" data-lazy-src="https://ali-oss.xmwpro.com/project/vue3-admin/logo.png"><span class="back-menu-item-text">Vue3-Admin</span></a><a class="back-menu-item" href="http://vue2.xmwpro.com/" rel="external nofollow noreferrer" title="Vue2-Admin" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="" data-lazy-src="https://ali-oss.xmwpro.com/project/vue2-admin/logo.svg"><span class="back-menu-item-text">Vue2-Admin</span></a><a class="back-menu-item" href="https://ele-plus-form.xmwpro.com/" rel="external nofollow noreferrer" title="vue3-form" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="" data-lazy-src="https://ali-oss.xmwpro.com/pages/resource/vue.svg"><span class="back-menu-item-text">vue3-form</span></a><a class="back-menu-item" href="https://ele-plus-table.xmwpro.com/" rel="external nofollow noreferrer" title="vue3-table" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="" data-lazy-src="https://ali-oss.xmwpro.com/pages/resource/vue.svg"><span class="back-menu-item-text">vue3-table</span></a></div></div></div></div><a id="site-name" href="/"><div class="title">Cyan</div><i class="fa-solid fa-house"></i></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page group faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw faa-tada fas fa-book"></i> <span>文库</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/archives/"><i class="fa-fw faa-tada fa-solid fa-box-archive"></i> <span>全部文章</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/tags/"><i class="fa-fw faa-tada fas fa-tags"></i> <span>标签</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/categories/"><i class="fa-fw faa-tada fas fa-shapes"></i> <span>分类</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw faa-tada fab fa-artstation"></i> <span>社交</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/link/"><i class="fa-fw faa-tada fa-solid fa-link"></i> <span>友人帐</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/fcircle/"><i class="fa-fw faa-tada fa-solid fa-user-group"></i> <span>朋友圈</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/guestbook/"><i class="fa-fw faa-tada fa-solid fa-envelope"></i> <span>留言板</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw faa-tada fas fa-coffee"></i> <span>休闲</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/music/"><i class="fa-fw faa-tada fa-solid fa-music"></i> <span>音乐馆</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/photoAlbum/"><i class="fa-fw faa-tada fa-solid fa-camera"></i> <span>相册</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/essay/"><i class="fa-fw faa-tada fa-solid fa-message"></i> <span>哔哔</span></a></li></ul></div><div class="menus_item"><a class="site-page group faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw faa-tada fa-solid fa-earth-asia"></i> <span>本站</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/analysis/"><i class="fa-fw faa-tada fa-solid fa-chart-simple"></i> <span>博客统计</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/about/"><i class="fa-fw faa-tada fa-regular fa-address-card"></i> <span>关于我</span></a></li></ul></div></div><center id="name-container"><span id="page-name" href="javascript:void(0);">PAGE_NAME</span></center></div><div id="nav-right"><div class="nav-button" id="search-button"><a class="social-icon search" href="javascript:void(0);" rel="external nofollow noreferrer" title="全局搜索"><i class="fas fa-search fa-fw"></i></a></div><div class="nav-button"><a class="social-icon" target="_blank" rel="noopener external nofollow noreferrer" href="https://travellings.cn/go.html" title="离开这里并访问下一个博客「开往服务」"><i class="fa-solid fa-subway"></i></a></div><div class="nav-button"><a class="social-icon random-post" href="javascript:toRandomPost();" rel="external nofollow noreferrer" title="随机前往一个文章"><i class="fa-solid fa-dice"></i></a></div><div class="nav-button" id="darkmode_navswitch"><a class="darkmode_switchbutton" type="button" title="浅色和深色模式转换" onclick="document.getElementById(&quot;darkmode&quot;).click()"><i class="fas fa-moon isMoon"></i><i class="fas fa-sun isSun"></i></a></div><div class="nav-button" id="go-up" title="回到顶部"><a class="totopbtn" href="javascript:void(0);" rel="external nofollow noreferrer"><span class="scroll-percent" onclick="btf.scrollToDest(0,500)"></span><i class="fas fa-arrow-up" onclick="btf.scrollToDest(0,500)"></i></a></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><div class="post-container"><div class="post-container-categories"><a class="categories-link" href="/categories/%E5%89%8D%E7%AB%AF%E5%BC%80%E5%8F%91/">前端开发</a></div><div class="post-container-tags"><a class="tags-link" href="/tags/%E7%BB%84%E4%BB%B6%E5%B0%81%E8%A3%85/"><span class="tags-punctuation">#</span><span class="tags-name">组件封装</span></a><a class="tags-link" href="/tags/React/"><span class="tags-punctuation">#</span><span class="tags-name">React</span></a><a class="tags-link" href="/tags/And-Design/"><span class="tags-punctuation">#</span><span class="tags-name">And Design</span></a></div></div><h1 class="post-title">React - 实现一个基于 Antd 的密码强度校验组件</h1><div id="post-meta"><div class="meta-secondline"><div class="post-meta-common post-meta-date" title="发表于 2023-01-16 16:35:22"><i class="fas fa-calendar fa-fw post-meta-icon"></i><time class="post-meta-date-created" datetime="2023-01-16T16:35:22.000Z">01-16</time></div><div class="post-meta-common post-meta-date" title="更新于 2023-06-26 09:26:36"><i class="fas fa-history fa-fw post-meta-icon"></i><time class="post-meta-date-updated" datetime="2023-01-16T16:35:22.000Z">06-26</time></div><div class="post-meta-common post-meta-wordcount" title="字数总计 1.1k"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="word-count">1.1k</span></div><div class="post-meta-common post-meta-read-time" title="阅读时长 5分钟"><i class="far fa-clock fa-fw post-meta-icon"></i><span>5分钟</span></div><div class="post-meta-common post-meta-region" title="作者的IP归属地为深圳"><i class="far fa-solid fa-location-dot post-meta-icon"></i><span>深圳</span></div><div class="post-meta-common post-meta-original" title="作者原创"><i class="far fa-solid fa-copyright post-meta-icon"></i><span>原创</span></div><div class="post-meta-common post-meta-commentcount" title="评论数" onclick='cyan.scrollTo("#post-comment")'><i class="fa-solid fa-comment fa-fw post-meta-icon"></i><a href="/post/e140163a.html#post-comment"><span id="twikoo-count"><i class="fa-solid fa-spinner fa-spin"></i></span></a></div></div></div></div><section class="main-hero-waves-area waves-area"><svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"><defs><path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s58 18 88 18 58-18 88-18 58 18 88 18v44h-352Z"></path></defs><g class="parallax"><use href="#gentle-wave" x="48" y="0"></use><use href="#gentle-wave" x="48" y="3"></use><use href="#gentle-wave" x="48" y="5"></use><use href="#gentle-wave" x="48" y="7"></use></g></svg></section></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><blockquote><p>最近在开发 Nest 和 Umi 技术栈的个人项目，在用户管理模块需要用到一个密码强度校验组件，在网上寻找一方资料，没有找到自己想要的，特此自己造轮子！</p></blockquote><h2 id="效果预览"><a href="#效果预览" class="headerlink" title="效果预览"></a>效果预览</h2><p><img src="" data-lazy-src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0bc7a5a860c5403cafed095e244fedb9~tplv-k3u1fbpfcp-watermark.image" alt="image.png"></p><h2 id="组件思想"><a href="#组件思想" class="headerlink" title="组件思想"></a>组件思想</h2><ol><li>既然是密码强度校验，那么强度就必须有个梯度，这个时候就必须找到一个合适的效果。</li><li>我们有两种方向：① 组件库找个合适的 UI ， ② 自己开发造轮子</li><li>经过一番摸索， Antd 的 Progress 组件进入了我的视野：</li></ol><p><img src="" data-lazy-src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2effb6eaf6c54a53bc42de9d50fb970c~tplv-k3u1fbpfcp-watermark.image" alt="image.png"></p><p>于是我决定基于这个组件改造一番！</p><h2 id="组件开发"><a href="#组件开发" class="headerlink" title="组件开发"></a>组件开发</h2><ol><li>在目录 <code>/src/components</code> 新建 <code>StrengthMeter/index.tsx</code> 文件，开发基本结构。<figure class="highlight tsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> * @Description: 密码强度组件</span></span><br><span class="line"><span class="comment"> * @Version: 2.0</span></span><br><span class="line"><span class="comment"> * @Author: Cyan</span></span><br><span class="line"><span class="comment"> * @Date: 2023-01-09 17:15:19</span></span><br><span class="line"><span class="comment"> * @LastEditors: Cyan</span></span><br><span class="line"><span class="comment"> * @LastEditTime: 2023-01-16 15:40:45</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">import</span> <span class="keyword">type</span> &#123; <span class="variable constant_">FC</span> &#125; <span class="keyword">from</span> <span class="string">&#x27;react&#x27;</span></span><br><span class="line"><span class="keyword">import</span> &#123; <span class="title class_">Progress</span>, <span class="title class_">Form</span>, <span class="title class_">Row</span>, <span class="title class_">Col</span> &#125; <span class="keyword">from</span> <span class="string">&#x27;antd&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> &#123; <span class="title class_">ProFormText</span> &#125; <span class="keyword">from</span> <span class="string">&#x27;@ant-design/pro-components&#x27;</span>; <span class="comment">// antd 高级组件</span></span><br><span class="line"><span class="keyword">import</span> zxcvbn <span class="keyword">from</span> <span class="string">&#x27;zxcvbn&#x27;</span>; <span class="comment">// 密码强度校验</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="title class_">StrengthMeter</span>: <span class="variable constant_">FC</span> = <span class="function">() =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// 获取上下文 form 实例</span></span><br><span class="line">  <span class="keyword">const</span> form = <span class="title class_">Form</span>.<span class="title function_">useFormInstance</span>();</span><br><span class="line">  <span class="comment">// 监听密码的改变</span></span><br><span class="line">  <span class="keyword">const</span> password = <span class="title class_">Form</span>.<span class="title function_">useWatch</span>(<span class="string">&#x27;password&#x27;</span>, form);</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@description</span>: 监听密码强度相应变化</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> &#123;<span class="type">string</span>&#125; <span class="variable">password</span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@return</span> &#123;<span class="type">*</span>&#125;</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@author</span>: Cyan</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="keyword">const</span> watchStrength = (<span class="attr">password</span>: <span class="built_in">string</span>): <span class="function"><span class="params">number</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> analysisValue = <span class="title function_">zxcvbn</span>(password)</span><br><span class="line">    <span class="comment">// score得分只有0~4，且只有整数范围并没有小数</span></span><br><span class="line">    <span class="keyword">return</span> (analysisValue.<span class="property">score</span> + <span class="number">1</span>) * <span class="number">20</span></span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> (</span><br><span class="line">    <span class="language-xml"><span class="tag">&lt;&gt;</span></span></span><br><span class="line"><span class="language-xml">      &#123;/* 密码 */&#125;</span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;<span class="name">ProFormText.Password</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">        <span class="attr">label</span>=<span class="string">&quot;密码&quot;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">        <span class="attr">name</span>=<span class="string">&quot;password&quot;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">        <span class="attr">rules</span>=<span class="string">&#123;[&#123;</span> <span class="attr">required:</span> <span class="attr">true</span>, <span class="attr">min:</span> <span class="attr">6</span>, <span class="attr">max:</span> <span class="attr">12</span>, <span class="attr">message:</span> &quot;<span class="attr">请输入密码</span>&quot; &#125;]&#125;</span></span></span><br><span class="line"><span class="tag"><span class="language-xml">      /&gt;</span></span></span><br><span class="line"><span class="language-xml">      &#123;/* 确认密码 */&#125;</span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;<span class="name">ProFormText.Password</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">        <span class="attr">label</span>=<span class="string">&quot;确认密码&quot;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">        <span class="attr">name</span>=<span class="string">&quot;confirmPassword&quot;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">        <span class="attr">fieldProps</span>=<span class="string">&#123;&#123;</span> <span class="attr">visibilityToggle:</span> <span class="attr">false</span> &#125;&#125;</span></span></span><br><span class="line"><span class="tag"><span class="language-xml">        <span class="attr">rules</span>=<span class="string">&#123;[</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">          &#123; <span class="attr">required:</span> <span class="attr">true</span>, <span class="attr">message:</span> &quot;<span class="attr">请输入确认密码</span>&quot; &#125;,</span></span></span><br><span class="line"><span class="tag"><span class="language-xml">          (&#123; <span class="attr">getFieldValue</span> &#125;) =&gt;</span> (&#123;</span></span><br><span class="line"><span class="language-xml">            validator(_, value) &#123;</span></span><br><span class="line"><span class="language-xml">              if (!value || getFieldValue(&#x27;password&#x27;) === value) &#123;</span></span><br><span class="line"><span class="language-xml">                return Promise.resolve();</span></span><br><span class="line"><span class="language-xml">              &#125;</span></span><br><span class="line"><span class="language-xml">              return Promise.reject(new Error(&quot;两次密码输入不一致&quot;));</span></span><br><span class="line"><span class="language-xml">            &#125;,</span></span><br><span class="line"><span class="language-xml">          &#125;)</span></span><br><span class="line"><span class="language-xml">        ]&#125;</span></span><br><span class="line"><span class="language-xml">      /&gt;</span></span><br><span class="line"><span class="language-xml">      &#123;/* 显示密码强度 */&#125;</span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;<span class="name">Progress</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">        <span class="attr">percent</span>=<span class="string">&#123;password</span> ? <span class="attr">watchStrength</span>(<span class="attr">password</span>) <span class="attr">:</span> <span class="attr">0</span>&#125;</span></span></span><br><span class="line"><span class="tag"><span class="language-xml">        <span class="attr">steps</span>=<span class="string">&#123;5&#125;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">        <span class="attr">strokeColor</span>=<span class="string">&#123;[</span>&#x27;#<span class="attr">e74242</span>&#x27;, &#x27;#<span class="attr">EFBD47</span>&#x27;, &#x27;#<span class="attr">ffa500</span>&#x27;, &#x27;#<span class="attr">1bbf1b</span>&#x27;, &#x27;#<span class="attr">008000</span>&#x27;]&#125;</span></span></span><br><span class="line"><span class="tag"><span class="language-xml">        <span class="attr">showInfo</span>=<span class="string">&#123;false&#125;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">      /&gt;</span></span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;<span class="name">Row</span> <span class="attr">justify</span>=<span class="string">&quot;space-around&quot;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">        &#123;</span></span><br><span class="line"><span class="language-xml">          [&#x27;非常弱&#x27;, &#x27;弱&#x27;, &#x27;一般&#x27;, &#x27;强&#x27;, &#x27;非常强&#x27;].map(value =&gt; <span class="tag">&lt;<span class="name">Col</span> <span class="attr">span</span>=<span class="string">&#123;4&#125;</span> <span class="attr">key</span>=<span class="string">&#123;value&#125;</span>&gt;</span>&#123;value&#125;  <span class="tag">&lt;/<span class="name">Col</span>&gt;</span>)</span></span><br><span class="line"><span class="language-xml">        &#125;</span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;/<span class="name">Row</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">    <span class="tag">&lt;/&gt;</span></span></span><br><span class="line">  )</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> <span class="title class_">StrengthMeter</span></span><br></pre></td></tr></table></figure></li><li>此时的效果是这样的：</li></ol><p><img src="" data-lazy-src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/b599ea7da53d4b14b4fb4e4d45d3c8c0~tplv-k3u1fbpfcp-watermark.image" alt="image.png"></p><p>由于 Progress 的 ant-progress-steps-item 无法自动撑开，我们需要新建一个 <code>index.module.less</code> 文件做样式穿透:</p><figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.process-steps</span>&#123;</span><br><span class="line">  <span class="attribute">width</span>:<span class="number">100%</span>;</span><br><span class="line">  <span class="attribute">text-align</span>: center;</span><br><span class="line">  :<span class="selector-tag">global</span>(.ant-progress)&#123;</span><br><span class="line">    <span class="attribute">width</span>:<span class="number">100%</span></span><br><span class="line">  &#125;</span><br><span class="line">  :<span class="selector-tag">global</span>(.ant-progress .ant-progress-steps-item)&#123;</span><br><span class="line">    <span class="attribute">width</span>:<span class="built_in">calc</span>(<span class="number">20%</span> - <span class="number">2px</span>) <span class="meta">!important</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>然后引入样式并绑定类名：</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> styles <span class="keyword">from</span> <span class="string">&#x27;./index.module.less&#x27;</span></span><br><span class="line"></span><br><span class="line">&lt;div className=&#123;styles[<span class="string">&#x27;process-steps&#x27;</span>]&#125;&gt;</span><br><span class="line">    <span class="language-xml"><span class="tag">&lt;<span class="name">Progress</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">      <span class="attr">percent</span>=<span class="string">&#123;password</span> ? <span class="attr">watchStrength</span>(<span class="attr">password</span>) <span class="attr">:</span> <span class="attr">0</span>&#125;</span></span></span><br><span class="line"><span class="tag"><span class="language-xml">      <span class="attr">steps</span>=<span class="string">&#123;5&#125;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">      <span class="attr">strokeColor</span>=<span class="string">&#123;[</span>&#x27;#<span class="attr">e74242</span>&#x27;, &#x27;#<span class="attr">EFBD47</span>&#x27;, &#x27;#<span class="attr">ffa500</span>&#x27;, &#x27;#<span class="attr">1bbf1b</span>&#x27;, &#x27;#<span class="attr">008000</span>&#x27;]&#125;</span></span></span><br><span class="line"><span class="tag"><span class="language-xml">      <span class="attr">showInfo</span>=<span class="string">&#123;false&#125;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">    /&gt;</span></span></span><br><span class="line">&lt;/div&gt;</span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">Row</span> <span class="attr">justify</span>=<span class="string">&quot;space-around&quot;</span> <span class="attr">className</span>=<span class="string">&#123;styles[</span>&#x27;<span class="attr">process-steps</span>&#x27;]&#125;&gt;</span></span></span><br><span class="line"><span class="language-xml">    &#123;</span></span><br><span class="line"><span class="language-xml">      [&#x27;非常弱&#x27;, &#x27;弱&#x27;, &#x27;一般&#x27;, &#x27;强&#x27;, &#x27;非常强&#x27;].map(value =&gt; <span class="tag">&lt;<span class="name">Col</span> <span class="attr">span</span>=<span class="string">&#123;4&#125;</span> <span class="attr">key</span>=<span class="string">&#123;value&#125;</span>&gt;</span>&#123;value&#125;<span class="tag">&lt;/<span class="name">Col</span>&gt;</span>)</span></span><br><span class="line"><span class="language-xml">    &#125;</span></span><br><span class="line"><span class="language-xml"><span class="tag">&lt;/<span class="name">Row</span>&gt;</span></span></span><br></pre></td></tr></table></figure><p>这时候就能得到我们想要的效果了，接下来我们要校验密码强度。<br>3. 这里我们要用到一个库：<a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/dropbox/zxcvbn">zxcvbn</a>，页面引入</p><figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> zxcvbn <span class="keyword">from</span> <span class="string">&#x27;zxcvbn&#x27;</span>;</span><br></pre></td></tr></table></figure><p><code>zxcvbn</code> 是个函数，接收一个参数，参数就是字符串密码。</p><figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title function_">zxcvbn</span>(<span class="string">&quot;abc123456&quot;</span>);</span><br></pre></td></tr></table></figure><p>该函数返回一个对象，其中与密码强度相关的属性有：<code>guesses</code>、<code>guesses_log10</code>、<code>score</code>。<br><img src="" data-lazy-src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/6dbceb41a1c2401ba7c136893bc4c2d7~tplv-k3u1fbpfcp-watermark.image" alt="image.png"><br>那么这三个属性，我们应该怎么选择呢？<br>①: guesses 值很大，不利于我们判断。<br>②: guesses_log10 的值越大越安全，根据测试，值在 <em>12</em> 以上就很安全了。<br>③: score 的取值范围只有整数 <em>0~4</em>，值越大越安全。<br>如果业务考虑的场景比较多，建议使用 guesses_log10，这里我们封装使用 score。<br>4. 使用 Form.useWatch 监听 password 的变化：</p><figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 获取上下文 form 实例</span></span><br><span class="line"><span class="keyword">const</span> form = <span class="title class_">Form</span>.<span class="title function_">useFormInstance</span>();</span><br><span class="line"><span class="comment">// 监听密码的改变</span></span><br><span class="line"><span class="keyword">const</span> password = <span class="title class_">Form</span>.<span class="title function_">useWatch</span>(<span class="string">&#x27;password&#x27;</span>, form);</span><br></pre></td></tr></table></figure><p>编写一个函数解析 password ：</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">const watchStrength = (password: string): number =&gt; &#123;</span><br><span class="line">    const analysisValue = zxcvbn(password)</span><br><span class="line">    // score得分只有0~4，且只有整数范围并没有小数</span><br><span class="line">    return (analysisValue.score + 1) * 20</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>绑定到 Progress 组件：</p><figure class="highlight tsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;<span class="title class_">Progress</span></span><br><span class="line">  percent=&#123;password ? <span class="title function_">watchStrength</span>(password) : <span class="number">0</span>&#125;</span><br><span class="line">  steps=&#123;<span class="number">5</span>&#125;</span><br><span class="line">  strokeColor=&#123;[<span class="string">&#x27;#e74242&#x27;</span>, <span class="string">&#x27;#EFBD47&#x27;</span>, <span class="string">&#x27;#ffa500&#x27;</span>, <span class="string">&#x27;#1bbf1b&#x27;</span>, <span class="string">&#x27;#008000&#x27;</span>]&#125;</span><br><span class="line">  showInfo=&#123;<span class="literal">false</span>&#125;</span><br><span class="line">/&gt;</span><br></pre></td></tr></table></figure><p>到这里，我们的任务就完成了，我们一起看看实际效果吧：</p><p><img src="" data-lazy-src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/23f784c89454489bbac3db6ac210eab5~tplv-k3u1fbpfcp-watermark.image" alt="动画.gif"></p><p>仓库地址：<a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/Cyan-Xmw/Xmw-Admin/blob/Cyan/Xmw_web/src/components/StrengthMeter/index.tsx">Xmw-Admin</a></p><p>如果对你有用，麻烦给个 star !</p></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者:</span> <span class="post-copyright-info"><a href="https://xmwpro.com">Cyan</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接:</span> <span class="post-copyright-info"><a href="https://xmwpro.com/post/e140163a.html">https://xmwpro.com/post/e140163a.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明:</span> <span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow noreferrer" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://xmwpro.com" target="_blank">Cyan</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E7%BB%84%E4%BB%B6%E5%B0%81%E8%A3%85/"><span class="tags-punctuation">#</span><span class="tags-name">组件封装</span><sup>5</sup></a><a class="post-meta__tags" href="/tags/React/"><span class="tags-punctuation">#</span><span class="tags-name">React</span><sup>7</sup></a><a class="post-meta__tags" href="/tags/And-Design/"><span class="tags-punctuation">#</span><span class="tags-name">And Design</span><sup>2</sup></a></div><div class="post_share"><div class="social-share" data-image="https://ali-oss.xmwpro.com/global/avatar.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://ali-oss.xmwpro.com/cdn/css/share.min.css" media="print" onload='this.media="all"'><script src="https://ali-oss.xmwpro.com/cdn/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://ali-oss.xmwpro.com/global/wx-pay.jpeg" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" src="" data-lazy-src="https://ali-oss.xmwpro.com/global/wx-pay.jpeg" alt="微信"></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://ali-oss.xmwpro.com/global/zfb-pay.jpeg" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" src="" data-lazy-src="https://ali-oss.xmwpro.com/global/zfb-pay.jpeg" alt="支付宝"></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/post/47e966c9.html" title="Nest.js系列(一)初次认识Nest"><img class="cover" src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover13.jpg" onerror='onerror=null,src="/img/404.jpg"' alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Nest.js系列(一)初次认识Nest</div></div></a></div><div class="next-post pull-right"><a href="/post/a1c66cd0.html" title="2022年回顾总结"><img class="cover" src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover32.jpg" onerror='onerror=null,src="/img/404.jpg"' alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">2022年回顾总结</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list swiper"><div class="swiper-wrapper"><div class="swiper-slide related-item"><a href="/post/e89dda9d.html" title="React - 实现一个基于 Antd 的下拉懒加载组件"><img class="cover" src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover1.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-10</div><div class="title">React - 实现一个基于 Antd 的下拉懒加载组件</div></div></a></div><div class="swiper-slide related-item"><a href="/post/ca4858a.html" title="基于 Vue3 + Element-plus 封装的 Table 组件"><img class="cover" src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover15.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-04-22</div><div class="title">基于 Vue3 + Element-plus 封装的 Table 组件</div></div></a></div><div class="swiper-slide related-item"><a href="/post/b8a1da20.html" title="基于 Vue3 + Element-plus 表单 Form 组件二次封装"><img class="cover" src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover45.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-04-25</div><div class="title">基于 Vue3 + Element-plus 表单 Form 组件二次封装</div></div></a></div><div class="swiper-slide related-item"><a href="/post/ddb8bcbc.html" title="Vue3 + Vite 构建组件库发布到 npm"><img class="cover" src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover27.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-06-14</div><div class="title">Vue3 + Vite 构建组件库发布到 npm</div></div></a></div><div class="swiper-slide related-item"><a href="/post/2b445cd9.html" title="React.js框架 + TSX 知识点归纳"><img class="cover" src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover1.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-07-04</div><div class="title">React.js框架 + TSX 知识点归纳</div></div></a></div><div class="swiper-slide related-item"><a href="/post/d3bfdf4d.html" title="create-react-app 配置代理"><img class="cover" src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover45.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-07-07</div><div class="title">create-react-app 配置代理</div></div></a></div><div class="swiper-slide related-item"><a href="/post/13d20048.html" title="create-react-app 配置路径别名"><img class="cover" src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover36.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-07-07</div><div class="title">create-react-app 配置路径别名</div></div></a></div><div class="swiper-slide related-item"><a href="/post/7b74bd27.html" title="基于 React + Nest 的后台应用"><img class="cover" src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover26.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-04-18</div><div class="title">基于 React + Nest 的后台应用</div></div></a></div><div class="swiper-slide related-item"><a href="/post/1ce87d42.html" title="使用 sort-imports 排序规则美化头部 import 代码"><img class="cover" src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover20.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-06-06</div><div class="title">使用 sort-imports 排序规则美化头部 import 代码</div></div></a></div></div><div class="related-swiper-scrollbar"></div></div></div><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i> <span>评论</span></div><div class="comment-tips">您无需删除空行，直接评论以获取最佳展示效果</div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div><div class="barrageswiper"><div class="swiper"><div class="swiper-wrapper"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-my"><div class="card-info-my-avatar"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/global/avatar.jpg" onerror='this.onerror=null,this.src="/img/friend_404.gif"' alt="avatar"></div><div class="card-info-my-name"><div class="card-info-my-name-welcome"></div><div class="card-info-my-name-text">谢明伟</div></div></div><div class="card-info-content"><b>记录学习、生活和有趣的事</b></div><div class="card-info-announcement">好好吃饭🍣 好好睡觉💤 敲敲代码💻 谈谈恋爱💑</div><div class="card-info-social"><div class="card-info-social-icon"><a class="social-icon" href="https://github.com/Cyan-Xmw" rel="external nofollow noreferrer" target="_blank" title="Github"><i class="iconfont cyan-github-fill"></i></a></div><a class="card-info-social-more" href="/about/"><i class="fas fa-circle-chevron-right"></i><span class="card-info-social-more-text">了解更多</span></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%88%E6%9E%9C%E9%A2%84%E8%A7%88"><span class="toc-number">1.</span> <span class="toc-text">效果预览</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E6%80%9D%E6%83%B3"><span class="toc-number">2.</span> <span class="toc-text">组件思想</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E5%BC%80%E5%8F%91"><span class="toc-number">3.</span> <span class="toc-text">组件开发</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="aside-list"><div class="aside-list-item no-cover"><a class="thumbnail" href="/post/a109015f.html" title="TS 中的类型验算,高级通用 API 实现"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover17.jpg" onerror='this.onerror=null,this.src="/img/404.jpg"' alt="TS 中的类型验算,高级通用 API 实现"></a><div class="content"><a class="title" href="/post/a109015f.html" title="TS 中的类型验算,高级通用 API 实现">TS 中的类型验算,高级通用 API 实现</a><time datetime="2023-06-26T15:26:24.000Z" title="发表于 2023-06-26 15:26:24">2023-06-26</time></div></div><div class="aside-list-item no-cover"><a class="thumbnail" href="/post/1ce87d42.html" title="使用 sort-imports 排序规则美化头部 import 代码"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover22.jpg" onerror='this.onerror=null,this.src="/img/404.jpg"' alt="使用 sort-imports 排序规则美化头部 import 代码"></a><div class="content"><a class="title" href="/post/1ce87d42.html" title="使用 sort-imports 排序规则美化头部 import 代码">使用 sort-imports 排序规则美化头部 import 代码</a><time datetime="2023-06-06T15:39:24.000Z" title="发表于 2023-06-06 15:39:24">2023-06-06</time></div></div><div class="aside-list-item no-cover"><a class="thumbnail" href="/post/b3e4ecaf.html" title="Vue 中如何监控用户网络状态"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover18.jpg" onerror='this.onerror=null,this.src="/img/404.jpg"' alt="Vue 中如何监控用户网络状态"></a><div class="content"><a class="title" href="/post/b3e4ecaf.html" title="Vue 中如何监控用户网络状态">Vue 中如何监控用户网络状态</a><time datetime="2023-05-22T16:08:02.000Z" title="发表于 2023-05-22 16:08:02">2023-05-22</time></div></div><div class="aside-list-item no-cover"><a class="thumbnail" href="/post/50b97751.html" title="在 vite 中使用 glob 实现约定式路由"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover43.jpg" onerror='this.onerror=null,this.src="/img/404.jpg"' alt="在 vite 中使用 glob 实现约定式路由"></a><div class="content"><a class="title" href="/post/50b97751.html" title="在 vite 中使用 glob 实现约定式路由">在 vite 中使用 glob 实现约定式路由</a><time datetime="2023-05-16T16:35:16.000Z" title="发表于 2023-05-16 16:35:16">2023-05-16</time></div></div><div class="aside-list-item no-cover"><a class="thumbnail" href="/post/7b74bd27.html" title="基于 React + Nest 的后台应用"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/posts/post_cover45.jpg" onerror='this.onerror=null,this.src="/img/404.jpg"' alt="基于 React + Nest 的后台应用"></a><div class="content"><a class="title" href="/post/7b74bd27.html" title="基于 React + Nest 的后台应用">基于 React + Nest 的后台应用</a><time datetime="2023-04-18T10:39:21.000Z" title="发表于 2023-04-18 10:39:21">2023-04-18</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="site-business"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/global/business.svg" alt="Cyan"></div><div class="site-services"><div class="site-services-link"><a class="site-services-link-item" href="https://www.aliyun.com/" rel="external nofollow noreferrer" target="_blank" title="阿里云提供cdn加速和云存储服务"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/global/aliyun.svg" alt="阿里云"></a><a class="site-services-link-item" href="https://www.foreverblog.cn/blog/4240.html/" rel="external nofollow noreferrer" target="_blank" title="十年之约虫洞服务"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/global/foreverblog-zh.svg" alt="十年之约"></a><a class="site-services-link-item" href="https://beian.miit.gov.cn/" rel="external nofollow noreferrer" target="_blank" title="粤ICP备2023007649号"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/global/icp.png" alt="粤ICP备2023007649号"><span>粤ICP备2023007649号</span></a><a class="site-services-link-item" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=44030402006264" rel="external nofollow noreferrer" target="_blank" title="粤公网安备44030402006264号"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/global/security.png" alt="粤公网安备44030402006264号"><span>粤公网安备44030402006264号</span></a></div></div><div class="footer_custom_text"><p style="margin:0"><a target="_blank" rel="noopener external nofollow noreferrer" href="https://hexo.io/" style="margin-inline:5px"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/global/hexo.svg" alt="博客框架 Hexo"></a><a target="_blank" rel="noopener external nofollow noreferrer" href="https://butterfly.js.org/" style="margin-inline:5px"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/global/Butterfly.svg" alt="主题 Butterfly"></a><a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/" style="margin-inline:5px"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/global/github.svg" alt="本站托管于 Github"></a><a target="_blank" rel="noopener external nofollow noreferrer" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" style="margin-inline:5px"><img src="" data-lazy-src="https://ali-oss.xmwpro.com/global/copyright.svg" alt="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可"></a></p></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="to_comment" type="button" title="直达评论" onclick='cyan.scrollTo("#post-comment")'><i class="fas fa-comments"></i></button><button id="toggle-barrage" type="button" title="开启/关闭弹幕" onclick="cyan.switchCommentBarrage()"><i class="iconfont cyan-barrage"></i></button><button id="toggle-music" type="button" title="播放/暂停音乐" onclick="cyan.musicToggle()"><i class="fas fa-solid fa-music"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="nav-music"><div id="nav-music-hoverTips" onclick="cyan.musicToggle()">播放音乐</div><meting-js id="6589687940" server="netease" type="playlist" mutex="true" preload="none" theme="var(--cyan-theme-color)" data-lrctype="0" order="random"></meting-js></div><div id="algolia-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">全局搜索</span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="search-wrap"><div id="algolia-search-input"></div><div id="algolia-search-results"><div id="algolia-hits"></div><div id="algolia-pagination"></div><div id="algolia-info"><div class="algolia-stats"></div><div class="algolia-poweredBy"></div></div></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://ali-oss.xmwpro.com/cdn/js/fancybox.umd.js"></script><script src="https://ali-oss.xmwpro.com/cdn/js/instantclick-1.2.2.js" type="module"></script><script src="https://ali-oss.xmwpro.com/cdn/js/lazyload.iife.min.js"></script><script src="https://ali-oss.xmwpro.com/cdn/js/snackbar.min.js"></script><script src="https://ali-oss.xmwpro.com/cdn/js/algoliasearch-lite.umd.min.js"></script><script src="https://ali-oss.xmwpro.com/cdn/js/instantsearch.production.min.js"></script><script src="/js/search/algolia.js"></script><div class="js-pjax"><script>(()=>{const o=()=>{twikoo.init(Object.assign({el:"#twikoo-wrap",envId:"https://twikoo.xmwpro.com/",region:"",onCommentLoaded:function(){btf.loadLightbox(document.querySelectorAll("#twikoo .tk-content img:not(.tk-owo-emotion)"))}},null)),GLOBAL_CONFIG_SITE.isPost&&(()=>{const o=document.getElementById("twikoo-count");o&&twikoo.getCommentsCount({envId:"https://twikoo.xmwpro.com/",region:"",urls:[window.location.pathname],includeReply:!1}).then((function(t){o.innerText=t[0].count})).catch((function(o){console.error(o)}))})()},t=()=>{"object"!=typeof twikoo?getScript("https://ali-oss.xmwpro.com/cdn/js/twikoo.all.min.js").then(o):setTimeout(o,0)};t()})()</script></div><script>window.addEventListener("load",(()=>{const e=e=>{let t="";if(e.length)for(let n=0;n<e.length;n++){t+="<div class='aside-list-item'>";{const a="data-lazy-src";t+=`<a href='${e[n].url}' class='thumbnail'><img ${a}='${e[n].avatar}' alt='${e[n].nick}'></a>`}t+=`<div class='content'>\n        <a class='comment' href='${e[n].url}' title='${e[n].content}'>${e[n].content}</a>\n        <div class='name'><span>${e[n].nick} / </span><time datetime="${e[n].date}">${btf.diffDate(e[n].date,!0)}</time></div>\n        </div></div>`}else t+="没有评论";let n=document.querySelector("#card-newest-comments .aside-list");n.innerHTML=t,window.lazyLoadInstance&&window.lazyLoadInstance.update(),window.pjax&&window.pjax.refresh(n)},t=()=>{if(document.querySelector("#card-newest-comments .aside-list")){const t=saveToLocal.get("twikoo-newest-comments");t?e(JSON.parse(t)):(()=>{const t=()=>{twikoo.getRecentComments({envId:"https://twikoo.xmwpro.com/",region:"",pageSize:6,includeReply:!0}).then((function(t){const n=t.map((e=>{return{content:(t=e.comment,""===t||(t=(t=(t=(t=t.replace(/<img.*?src="(.*?)"?[^\>]+>/gi,"[图片]")).replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi,"[链接]")).replace(/<pre><code>.*?<\/pre>/gi,"[代码]")).replace(/<[^>]+>/g,"")).length>150&&(t=t.substring(0,150)+"..."),t),avatar:e.avatar,nick:e.nick,url:e.url+"#"+e.id,date:new Date(e.created).toISOString()};var t}));saveToLocal.set("twikoo-newest-comments",JSON.stringify(n),10/1440),e(n)})).catch((function(e){document.querySelector("#card-newest-comments .aside-list").innerHTML="无法获取评论，请确认相关配置是否正确"}))};"object"==typeof twikoo?t():getScript("https://ali-oss.xmwpro.com/cdn/js/twikoo.all.min.js").then(t)})()}};t(),document.addEventListener("pjax:complete",t)}))</script><script async data-pjax src="/js/custom.js"></script><script async data-pjax src="/js/cascade.js"></script><script defer data-pjax src="//at.alicdn.com/t/c/font_3348168_pqjhlyxfz9r.js"></script><script async src="/js/commentBarrage.js"></script><script async data-pjax src="/js/sky.js"></script><script src="https://sdk.51.la/perf/js-sdk-perf.min.js" crossorigin="anonymous"></script><script>LA.init({id:"JxZKIeqz3SoTqaVu",ck:"JxZKIeqz3SoTqaVu"})</script><script>(new LingQue.Monitor).init({id:"JxZKIeqz3SoTqaVu",sendSuspicious:!0})</script><script src="/cyan/random.js"></script><script>let tianliGPT_postSelector="#post #article-container",tianliGPT_key="nWP7yQwRFXvk0piPhO2w"</script><script data-pjax src="https://ali-oss.xmwpro.com/cdn/js/tianli_gpt.js"></script><link rel="stylesheet" href="https://ali-oss.xmwpro.com/cdn/css/APlayer.min.css" media="print" onload='this.media="all"'><script src="https://ali-oss.xmwpro.com/cdn/js/APlayer.min.js"></script><script src="https://ali-oss.xmwpro.com/cdn/js/Meting.min.js"></script><script src="https://ali-oss.xmwpro.com/cdn/js/pjax.min.js"></script><script>let pjaxSelectors=["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"];var pjax=new Pjax({elements:'a:not([target="_blank"]):not([href="/tags/"]):not([href="/categories/"]):not([href="/analysis/"]):not([href="/fcircle/"])',selectors:pjaxSelectors,cacheBust:!1,analytics:!0,scrollRestoration:!1});document.addEventListener("pjax:send",(function(){if(window.tocScrollFn&&window.removeEventListener("scroll",window.tocScrollFn),window.scrollCollect&&window.removeEventListener("scroll",scrollCollect),document.getElementById("rightside").style.cssText="opacity: ''; transform: ''",window.aplayers)for(let e=0;e<window.aplayers.length;e++)window.aplayers[e].options.fixed||window.aplayers[e].destroy();"object"==typeof typed&&typed.destroy();const e=document.body.classList;e.contains("read-mode")&&e.remove("read-mode"),"object"==typeof disqusjs&&disqusjs.destroy()})),document.addEventListener("pjax:complete",(function(){window.refreshFn(),document.querySelectorAll("script[data-pjax]").forEach((e=>{const t=document.createElement("script"),o=e.text||e.textContent||e.innerHTML||"";Array.from(e.attributes).forEach((e=>t.setAttribute(e.name,e.value))),t.appendChild(document.createTextNode(o)),e.parentNode.replaceChild(t,e)})),GLOBAL_CONFIG.islazyload&&window.lazyLoadInstance.update(),"function"==typeof chatBtnFn&&chatBtnFn(),"function"==typeof panguInit&&panguInit(),"function"==typeof gtag&&gtag("config","G-2P0LMHZNDD",{page_path:window.location.pathname}),"object"==typeof _hmt&&_hmt.push(["_trackPageview",window.location.pathname]),"function"==typeof loadMeting&&document.getElementsByClassName("aplayer").length&&loadMeting(),"object"==typeof Prism&&Prism.highlightAll()})),document.addEventListener("pjax:error",(e=>{404===e.request.status&&pjax.loadUrl("/404.html")}))</script></div><script>var fdata={apiurl:"https://friend-api.xmwpro.com/",initnumber:30,stepnumber:30,error_img:"https://npm.elemecdn.com/akilar-candyassets/image/404.gif"};localStorage.setItem("fdatalist",JSON.stringify(fdata))</script><script data-pjax src="https://ali-oss.xmwpro.com/cdn/js/fetch-friend.js"></script><script data-pjax src="https://ali-oss.xmwpro.com/cdn/js/random-friends-post.js"></script><script async src="//at.alicdn.com/t/c/font_3344355_6og082zqzfd.js"></script><div class="js-pjax"><script async>for(var arr=document.getElementsByClassName("recent-post-item"),i=0;i<arr.length;i++)arr[i].classList.add("wow"),arr[i].classList.add("animate__zoomIn"),arr[i].setAttribute("data-wow-duration",""),arr[i].setAttribute("data-wow-delay",""),arr[i].setAttribute("data-wow-offset","20"),arr[i].setAttribute("data-wow-iteration","")</script><script async>for(var arr=document.getElementsByClassName("bbTimeList"),i=0;i<arr.length;i++)arr[i].classList.add("wow"),arr[i].classList.add("animate__zoomIn"),arr[i].setAttribute("data-wow-duration",""),arr[i].setAttribute("data-wow-delay",""),arr[i].setAttribute("data-wow-offset","20"),arr[i].setAttribute("data-wow-iteration","")</script><script async>for(var arr=document.getElementsByClassName("card-widget"),i=0;i<arr.length;i++)arr[i].classList.add("wow"),arr[i].classList.add("animate__zoomIn"),arr[i].setAttribute("data-wow-duration",""),arr[i].setAttribute("data-wow-delay",""),arr[i].setAttribute("data-wow-offset","20"),arr[i].setAttribute("data-wow-iteration","")</script><script async>for(var arr=document.getElementsByClassName("category-in-bar"),i=0;i<arr.length;i++)arr[i].classList.add("wow"),arr[i].classList.add("animate__zoomIn"),arr[i].setAttribute("data-wow-duration",""),arr[i].setAttribute("data-wow-delay",""),arr[i].setAttribute("data-wow-offset","20"),arr[i].setAttribute("data-wow-iteration","")</script><script async>for(var arr=document.getElementsByClassName("bber-item"),i=0;i<arr.length;i++)arr[i].classList.add("wow"),arr[i].classList.add("animate__fadeInUp"),arr[i].setAttribute("data-wow-duration","1.5s"),arr[i].setAttribute("data-wow-delay",""),arr[i].setAttribute("data-wow-offset","20"),arr[i].setAttribute("data-wow-iteration","")</script><script async>for(var arr=document.getElementsByClassName("statistics-item"),i=0;i<arr.length;i++)arr[i].classList.add("wow"),arr[i].classList.add("animate__zoomIn"),arr[i].setAttribute("data-wow-duration","1.5s"),arr[i].setAttribute("data-wow-delay",""),arr[i].setAttribute("data-wow-offset","20"),arr[i].setAttribute("data-wow-iteration","")</script></div><script defer src="https://ali-oss.xmwpro.com/cdn/js/wow.min.js"></script><script defer src="https://ali-oss.xmwpro.com/cdn/js/wow_init.js"></script><script data-pjax src="https://ali-oss.xmwpro.com/cdn/js/gitcalendar.js"></script><script data-pjax>function gitcalendar_injector_config(){document.getElementById("recent-posts").insertAdjacentHTML("afterbegin",'<div class="recent-post-item" id="gitcalendarBar" style="width:100%;height:auto;padding:10px;"><style>#git_container{min-height: 280px}@media screen and (max-width:650px) {#git_container{min-height: 0px}}</style><div id="git_loading" style="width:10%;height:100%;margin:0 auto;display: block;"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50" xml:space="preserve"><path fill="#d0d0d0" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z" transform="rotate(275.098 25 25)"><animatetransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"></animatetransform></path></svg><style>#git_container{display: none;}</style></div><div id="git_container"></div></div>'),console.log("已挂载gitcalendar")}document.getElementById("recent-posts")&&"/"===location.pathname&&(gitcalendar_injector_config(),GitCalendarInit("https://github-calendar.xmwpro.com/api?Cyan-Xmw",["#e3f2fd","#bbdefb","#90caf9","#64b5f6","#42a5f5","#2196f3","#1e88e5","#1976d2","#1565c0","#0d47a1","#425AEF"],"Cyan-Xmw"))</script></body></html>